<?php echo $this->Html->css(array('front/forms')); ?>
<!--[body]-->
<style>
    .checkbox{
        width: 35px;
        float: left;
    }
    .text{
        float: left;
        width: 270px;
    }
    .select{
        float: left;
        width: 270px;
    }

</style>

<div id="body">
    <div class="inner-container">
        <h1 style="color:#0B91C2; font-size: 22px; padding-bottom: 10px;">My profile / Voting History </h1>
        <?php echo  $this->Html->link('View Profile',array('controller'=>'Profiles','action'=>'profile'),array('style'=>'font-size:14px;font-weight:bold;text-decoration:underline;color:#15ADFF;font-family:"Lucida Sans Unicode","Lucida Grande",sans-serif')); ?>
<?php echo $this->Form->create('Profiles', array('class' => 'profile-form', 'action' => 'profile_edit','type'=>'file')) ?>
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr valign="top">
                <td width="50%"  valign="top"><table width="100%" border="0" cellspacing="0" cellpadding="0">
                        
                        <tr>
                            <td colspan="2">
                                <table width="100%" border="0" cellspacing="0" cellpadding="0">
                                    <tr>
                                        <td width="37%"><label> You have </label></td>
                                        <td width="63%"><span style="font-size: 22px; color:#0B91C2;font-weight: bold;"><?php echo $points; ?> </span>points</td>
                                    </tr>
                                    <tr>
                                        <td><label> You ranks  </label></td>
                                        <td><span style="font-size: 22px; color:#0B91C2;font-weight: bold;"><?php echo $rank['rank']; ?></span> on the site</td>
                                    </tr>
                                    <tr>
                                        <td><label> You have rated </label></td>
                                        <td><span style="font-size: 22px; color:#0B91C2;font-weight: bold;"><?php echo $subjects_rated; ?> </span> Subjects</td>
                                    </tr>
                                    <tr>
                                        <td><label> You have added </label></td>
                                        <td><span style="font-size: 22px; color:#0B91C2;font-weight: bold;"><?php echo $subject_added; ?></span>  Subjects</td>
                                    </tr>
                                    <tr>
                                        <td><label> You are at </label></td>
                                        <td><span style="font-size: 22px; color:#0B91C2;font-weight: bold;">
                                        <?php
                        if (!isset($points))
                            $points='0';
                        $points=$points;
                            if($points<999){
                                $level="Cosmic Dust";
                            }else if($points>999 && $points<2999){
                                $level="Planet";
                            }else if($points>2999 && $points<4999){
                                $level="Star";
                            }else if($points>4999 && $points<9999){
                                $level="Gelaxy";
                            }else if($points>9999 && $points<100000){
                                $level="Black Hole";
                            }else if($points>100000 && $points<1000000){
                                $level="Supernova";
                            }else if($points>1000000){
                                $level="Quantum";
                            }
        
                        echo $level; ?></span>  Level</td>
                                    </tr>
                                </table>
                                
                            </td>
                        </tr>
                        <tr>
                            <th colspan="2">Login details</th>
                        </tr>
                        
                        <tr>
                            <td width="37%"><label>Email:</label></td>
                            <td width="63%"><?php echo $_SESSION['Auth']['user']['User']['email']; ?></td>
                        </tr>
                        <tr>
                            <td><label>Password</label></td>
                            <td>
                                <div id="screen_error" style="color:#D64937"></div>
                                <div id="password-input" style="display: none">
                                    <?php echo $this->Form->input('User.password',array('label'=>'','value'=>'','id'=>'password')); ?>
                                </div>
                                <div id="password-change" style="display:block;"><a  href="#"><span id="change-password">Change Password</span></a></div>
                            </td>
                        </tr><tr>
                            <td><label>Screen Name:</label></td>
                            <td>
                                <div id="screen_error" style="color:#D64937"></div>
                                <div id="screen-name-input" style="display: <?php if(empty($profile['UserProfile']['screenname'])){ echo "block";}else{echo 'none';} ?>">
                                    <?php echo $this->Form->input('UserProfile.screenname',array('label'=>'','value'=>$profile['UserProfile']['screenname'],'id'=>'screenname')); ?>
                                </div>
                                <div id="screen-name" style="display: <?php if(empty($profile['UserProfile']['screenname'])){ echo "none";}else{echo 'block';} ?>"><?php echo $profile['UserProfile']['screenname'];?> <a  href="#" style="margin-left: 50px;"><span id="change-name">Change</span></a></div>
                            </td>
                        </tr>
                        
                        <tr>
                            <td width="37%"><label>Date of Birth:</label></td>
                            <td width="63%"><?php echo $this->Form->input('UserProfile.dob',array('label'=>'','minYear'=>'1930','maxYear'=>date('Y'),'value'=>$profile['UserProfile']['dob'],'id'=>'dob')); ?></td>
                        </tr>     
                        <tr>
                            <td><label>Picture:</label></td>
                            <td><div id="deleteimage"><?php
$thumbnail = $this->PhpThumb->generate(
        array(
            'save_path' => WWW_ROOT . 'img/uploads/Subjects/thumbs',
            'display_path' => 'uploads/Subjects/thumbs',
            'error_image_path' => 'noimage.png',
            'src' => WWW_ROOT . "img/uploads/profileimage/" . $profile['UserProfile']['image'],
            'w' => 120,
            'h' => 150,
            'q' => 100,
            'zc' => 1
        )
);
echo $this->Html->image($thumbnail['src'], array('width' => $thumbnail['w'], 'height' => $thumbnail['h'], 'class' => 'display-image'));
?></div>
                                <div id="imagechange" style="float: left; margin-left: -140px; margin-top: 170px;"><a id="change_image" href="#">Click to change Image</a></div>

                            </td>
                        </tr>
                        <tr>
                            <td colspan="1" height="15"></td>
                        </tr>
                        <tr>
                            <td colspan="2"> All info entered is private, the more info you share the more info/statistics we share with you. You can control how much information you would like share with others by selecting the field with the check-box. </td>
                        </tr>
<?php
$value='';
foreach ($profilefield as $pf):
    if ($pf['ProfileField']['type'] == 'text') {
        if (isset($pf['ProfileFieldValue']['value'])) {
            $value = $pf['ProfileFieldValue']['value'];
        }
        ?>
                                <tr>
                                    <td><label><?php echo $pf['ProfileField']['title'] ?>:</label></td>
                                    <td> 

                                        <?php echo $this->Form->input($pf['ProfileField']['id'], array('label' => '', 'value' => @$value, 'class' => 'input-pro')) ?>
                                        <?php
                                        if (isset($pf['ProfileFieldValue']['status']) && $pf['ProfileFieldValue']['status'] == '1') {
                                            $checked = 'true';
                                        } else {
                                            $checked = '';
                                        }
                                        ?>
                                    </td>   
                                    <td>

                                        <span>
        <?php echo $this->Form->input('status' . $pf['ProfileField']['id'], array('label' => '', 'type' => 'checkbox', 'checked' => $checked)); ?> 
                                        </span>
                                    </td>
                                </tr>
        <?php
    } else if ($pf['ProfileField']['type'] == 'select') {
        $option = explode(',', $pf['ProfileField']['value']);
        ?>
                                <tr>
                                    <td><label><?php echo $pf['ProfileField']['title'] ?>:</label></td>
                                    <td>    
                                        <select class="select-pro" name="data[Profiles][<?php echo $pf['ProfileField']['id']; ?>]" id="Profile<?php echo $pf['Profilefield']['id']; ?>">
                                            <option value="">--select--</option>
        <?php
        foreach ($option as $op):
            if ($op == $pf['ProfileFieldValue']['value']) {
                $select = 'selected="selected"';
            } else {
                $select = '';
            }
            ?>
                                                <option <?php echo $select; ?> value="<?php echo $op; ?>"><?php echo $op; ?></option>
                                            <?php endforeach; ?>
                                        </select>

                                    </td>
                                    <td>
        <?php
        if ( isset($pf['ProfileFieldValue']['status']) && $pf['ProfileFieldValue']['status'] == '1') {
            $checked = 'true';
        } else {
            $checked = '';
        }
        ?>
                                        <span>
                                        <?php echo $this->Form->input('status' . $pf['ProfileField']['id'], array('label' => '', 'type' => 'checkbox', 'checked' => $checked)); ?> 
                                        </span>
                                    </td>
                                </tr>
        <?php
    } else if ($pf['ProfileField']['type'] == 'textarea') {
        if(isset($pf['ProfileFieldValue']['value'])){
            $value=$pf['ProfileFieldValue']['value'];
        }
        ?>
                                <tr>
                                    <td><label><?php echo $pf['ProfileField']['title'] ?>:</label></td>
                                    <td style="float: left;" valign="top">    
        <?php echo $this->Form->input($pf['ProfileField']['id'], array('label' => '', 'value' => $value, 'rows' => '3', 'cols' => '35', 'type' => 'textarea')) ?>

                                    </td>
                                    <td> 
        <?php
        if (isset($pf['ProfileFieldValue']['status']) && $pf['ProfileFieldValue']['status'] == '1') {
            $checked = 'true';
        } else {
            $checked = '';
        }
        ?> 
                                        <span>
                                        <?php echo $this->Form->input('status' . $pf['ProfileField']['id'], array('label' => '', 'type' => 'checkbox', 'checked' => $checked)); ?> 
                                        </span>
                                    </td>
                                </tr>
                                            <?php
                                        } else if ($pf['ProfileField']['type'] == 'checkbox') {
                                            $value = explode(',', $pf['ProfileField']['value']);
                                            ?>
                                <tr>
                                    <td><label><?php echo $pf['ProfileField']['title'] ?>:</label></td>
                                    <td> 
                                <?php
                                $checked = "";
                                $i = 0;
                                $check = explode(',', $pf['ProfileFieldValue']['value']); //debug($check);
                                foreach ($value as $vl) :
                                    if (in_array($vl, $check)) {

                                        $checked = 'checked="true"';
                                    } else {
                                        $checked = '';
                                    }
                                    ?>
                                            <div class="checkbox"><input type="checkbox" id="Profiles<?php echo $pf['ProfileField']['id']; ?>" value="<?php echo $vl; ?>" <?php echo $checked; ?> name="data[Profiles][<?php echo $pf['ProfileField']['id']; ?>][]"><label for="Profiles<?php echo $vl; ?>"><?php echo $vl; ?></label></div>
                                            <?php $i++;
                                        endforeach; ?>
                                        <?php // echo $form->input($pf['Profilefield']['id'], array('type'=>'select','label'=>'', 'multiple'=>'checkbox', 'options'=>$value)); ?>
                                        <?php
                                        if ($pf['ProfileFieldValue']['status'] == '1') {
                                            $checked = 'true';
                                        } else {
                                            $checked = '';
                                        }
                                        ?> 
                                    </td>
                                    <td> 
                                        <span>
        <?php echo $this->Form->input('status' . $pf['ProfileField']['id'], array('label' => '', 'type' => 'checkbox', 'checked' => $checked)); ?> 
                                        </span>
                                    </td>
                                </tr>
        <?php
    }
endforeach;
?>
                        <tr>
                            <td colspan="2"> 
<?php echo $this->Form->end(array('value' => '', 'class' => 'save-btn')); ?>
                            </td>
                        </tr>

                        <tr><td colspan="2"><a href="#">Demographic Research Tool </a></td></tr>
                    </table></td>
                <td width="50%"  style="background:#f3f3f3; padding:10px; border: 1px solid #dcdcdc;
                    border-radius: 4px 4px 4px 4px;">
<?php echo $this->Form->create('Payment', array('id' => 'payment_gateway', 'url' => 'https://www.sandbox.paypal.com/cgi-bin/webscr')); ?>
         <table width="100%" border="0" cellspacing="0" cellpadding="0">
                        <tr>
                            <th colspan="2" >Upgrade my account</th>
                        </tr>
                        <tr>
                            <td colspan="2" height="10"></td>
                        </tr>
                        <tr>
                            <td width="10%"  ><input name="payment" type="radio" value="free" id="free" checked /></td>
                            <td width="90%"><strong>Free account</strong></td>
                        </tr>
                        <tr>
                            <td colspan="2" height="20"></td>
                        </tr>
<?php foreach ($plan as $plans) : ?>
                            <tr>
                                <td  >&nbsp;</td>
                                <td><strong><?php echo ucwords($plans['Memberplan']['title']); ?></strong><br />
                                    Free <em><?php echo $week = $plans['Memberplan']['duration'] / 7; ?>&nbsp;week</em> trial at every <em><?php echo $plans['Memberplan']['points']; ?></em> point level. </td>
                            </tr>
                            <tr>
                                <td colspan="2" height="10"></td>
                            </tr>
                            <?php
                            $po = explode(',', $plans['Memberplan']['period']);
                            $pr = explode(',', $plans['Memberplan']['price']);
                            $cou = '0';
                            foreach ($pr as $prs) : 
                                if(isset($prs[$cou])){
                                    $prs=$prs[$cou];
                                }
                                if ($prs != "") {
                                    if ($cou % 2 == 0) {
                                        $day = 'Month';
                                    } else {
                                        $day = 'Year';
                                    }
                                    ?>
                                    <tr>
                                        <td><input name="payment" title="<?php echo ucwords($plans['Memberplan']['title']); ?>" abc="<?php echo $po[$cou].$day; ?>"  type="radio" value="<?php echo $pr[$cou]; ?>" /></td>
                                        <td>for <span class="font-color">$<?php echo $pr[$cou]; ?>/<?php echo $po[$cou]; ?>&nbsp;<?php echo $day; ?></span></td>
                                    </tr>
                                    <tr>
                                        <td colspan="2" height="10"></td>
                                    </tr>
                                                <?php $cou++;
                                            } endforeach; ?>
                            <tr><td  >&nbsp;</td>
                                <td><ul>
                                        <?php
                                        if ($plans['Memberplan']['option1'] == 0) {
                                            $class1 = 'class="inactive"';
                                        } else {
                                            $class1 = '';
                                        }
                                        if ($plans['Memberplan']['option2'] == 0) {
                                            $class2 = 'class="inactive"';
                                        } else {
                                            $class2 = '';
                                        }
                                        if ($plans['Memberplan']['option3'] == 0) {
                                            $class3 = 'class="inactive"';
                                        } else {
                                            $class3 = '';
                                        }
                                        ?>
                                        <li <?php echo $class1; ?>> <?php echo $text['0']['Memberplantext']['text']; ?></li>
                                        <li <?php echo $class2; ?>> <?php echo $text['1']['Memberplantext']['text']; ?></li>
                                        <li <?php echo $class3; ?>> <?php echo $text['2']['Memberplantext']['text']; ?></li>

                                    </ul></td>
                            </tr>
<?php endforeach; ?>
                        <tr>
                            <td colspan="2" height="20"></td>
                        </tr>
                        <tr>
                            <td colspan="2" height="40"></td>
                        </tr>
                        <tr><td colspan="2"><a href="#">Click Here to learn more about your account options and features </a></td></tr>

                    </table>
                   
                    <br/>
                    <input type="hidden"  name="cmd" value="_xclick" />
                    <input type="hidden" name="business" value="rajukumar.shinedezign@gmail.com" />
                    <input type="hidden" id="item_name" name="item_name" value="" />
                    <input type="hidden" id="amount" name="amount" value="" />
                    <input type="hidden" id="duration1" name="item_number" value="" />
                    <input type="hidden" name="notify_url" value="http://www.primeag.org/dev/ratetheu/PayPal_IPN_Process.php"/>
                    <input type="hidden" name="currency_code" value="USD" />
                    <input type="hidden" name="currency_code" value="USD" />
                    <input type="hidden" name="return" value="http://www.primeag.org/dev/ratetheu/Profiles/payment"/>

<?php echo $this->Form->end('https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif'); ?>
                </td>
            </tr>
        </table>

    </div>
</div>
<!--[/body]-->
<script>
    $(document).ready(function(){
         var base_url=$('#base-url').text();
        $("#change_image").click(function(){
           // alert("hello");
            $.ajax({
                url:base_url+'/Profiles/change_image',
                type:'POST',
                data:"image='<?php  echo $_SESSION['Auth']['user']['User']['id']; ?>'",
                success:function(response){
                    $('#deleteimage').html(response);
                    $("#imagechange").css('display','none');
                    $('#deleteimage').html('<input type="file" name="image" id="image" />');
                    
                }
            });
                       
            return false;
        });
        $(".save-btn").attr('value',''); 
        $("#payment_gateway").submit(function(){
            var value=$('input:radio[name=payment]:checked').val();
            var value1=$('input:radio[name=payment]:checked').attr('title');
            var value2=$('input:radio[name=payment]:checked').attr('abc');
             
            if(value=='free'){
                return false
            }else{
                $("#item_name").attr("value",value1);
                $("#amount").attr("value",value);
                $("#duration1").attr("value",value2);
                
                return true;
            }
               
            return false;
        });
        $('#change-name').click(function(){
            $('#screen-name').fadeOut();
            $('#screen-name-input').delay(400).fadeIn(400);
            
        });
        $('#change-password').click(function(){
            $('#password-change').fadeOut();
            $('#password-input').delay(400).fadeIn(400);
            
        });
        
        $('#screenname').keyup(function(){
            if($(this).val().length>1){
            $.ajax({
                url:base_url+'/Profiles/check_screenname',
                type:'POST',
                data:{name:$(this).val()},
                success:function(response){
                    if(response>0){
                        $('#screen_error').html('Screen Name Taken. Please choose another.');
                    }else{
                       $('#screen_error').empty(); 
                    }
                    
                }
            });
            }
        });
        
  $('#ProfilesProfileEditForm').submit(function(){
  $.ajax({
      url:base_url+'/Profiles/check_screenname',
      type:'POST',
      data:{name:$('#screenname').val()},
      success:function(response){
         
         if(response>0){
              $('#screen_error').html('Screen Name Taken. Please choose another.');
         
          }else{
            $('#screen_error').empty(); 
          }
         
      }
  });
  if($('#screen_error').is(':empty')){
      return true;
  }else{
      return false;
  }
  });
  $('#screenname').live('keypress',function(event) {
  var valid=[65,66,67,68,69,70,71,72,73,74,75,76,77,78,79,80,81,82,83,84,85,86,87,88,89,90,48,49,50,51,52,53,54,55,56,57,97,98,99,100,101,102,103,104,105,106,107,108,109,110,111,112,113,114,115,116,117,118,119,120,121,122,8,0];
 if ($.inArray(event.which,valid)==-1) {
       event.preventDefault();
    }
});

    });
</script>

